package com.tank.jdk8.stream;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/1/29
 * Time: 19:02
 * To change this template use File | Settings | File Templates.
 */
public class StreamTest4 {

    public static void main(String[] args) {


//        Stream<String> stream = Stream.generate(() -> null);
//        System.out.println("stream:"+stream);
//        Optional<String> first = stream.findFirst();
//        System.out.println("first:"+first);
      //  first.ifPresent((s) -> System.out.println());

        //iterate返回一个无尽头的流,需要使用limit进行限制
        //过滤filter
        //映射 map
        //跳过 忽略 skip
        //限制 截取 limit
        Stream<Integer> stream = Stream.iterate(1,(item) -> item+2).limit(6);
        System.out.println(stream.filter(item -> item > 2).mapToInt(item -> item * 2).skip(2).limit(2).min().getAsInt());

        //大于2 每个元素乘以2，忽略前2个元素，取流中2个元素求和
    }
}

